package com.umakr.ax.app.web;

import com.umakr.ax.app.service.UserWebRelationService;
import com.umakr.ax.core.base.AbstractController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * <p>
 * 标签  前端控制器
 * </p>
 *
 * @author Umakr-Code-Generator
 * @since 2017-12-30
 */
@Controller
@RequestMapping("/api/web/admin")
public class AccountWebController extends AbstractController {

	@Autowired
	UserWebRelationService userRelationService;

	@ApiOperation(value = "根据电台id返回电台账号列表")
	@GetMapping(value = "/listAccountByRsId")
	public Object listAccountByRsId(ModelMap modelMap, @RequestParam(name = "rsId") Long rsId) {
		return setSuccessModelMap(modelMap,userRelationService.listAccountByRsId(rsId));
	}

	@ApiOperation(value = "添加或修改电台账号")
	@PostMapping(value = "/saveOrUpdateAccount")
	public Object saveOrUpdateAccount(ModelMap modelMap,
									@RequestParam(name = "userId") Long userId,
									@RequestParam(name = "rsId") Long rsId,
									@RequestParam(name = "account") String account,
									@RequestParam(name = "nickname") String nickname,
									@RequestParam(name = "password") String password,
									@RequestParam(name = "roleName") Integer roleName,
									@RequestParam(name = "status") Integer status,
									@RequestParam(name = "type") Integer type) {
		return setSuccessModelMap(modelMap,userRelationService.saveOrUpdateAccount(userId,rsId,account,nickname,
				password,roleName,status,type));
	}

	@ApiOperation(value = "根据userId删除电台账号")
	@GetMapping(value = "/delectAccount")
	public Object delectAccount(ModelMap modelMap, @RequestParam(name = "userId") Long userId) {
		return setSuccessModelMap(modelMap,userRelationService.delectAccount(userId));
	}

	@ApiOperation(value = "验证新增账号的唯一性")
	@GetMapping(value = "/validateAccountOnly")
	public Object validateAccountOnly(ModelMap modelMap, @RequestParam(name = "account") String account) {
		return setSuccessModelMap(modelMap,userRelationService.validateAccountOnly(account));
	}

}